package com.mobiusws.util;

import java.io.InputStream;
import java.util.LinkedList;
import java.util.List;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.springframework.stereotype.Component;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import com.mobiusws.reports.model.DashboardReportInfo;

@Component("sqlUtil")
public class SqlUtil {
	private DocumentBuilder documentBuilder;
	private Document document;
	
    public SqlUtil() {
    	//initDoc();
    }
    
    private void initDoc() {
		try {
			documentBuilder = DocumentBuilderFactory.newInstance()
					.newDocumentBuilder();
			document=this.getDocument();
		} catch (Exception e) {
			e.printStackTrace();
		}
    }
    
	private Document getDocument() throws Exception {
		Document doc = null;
		InputStream in = SqlUtil.class
				.getResourceAsStream("/com/mobiusws/resources/sql.xml");
		//System.out.println((documentBuilder==null)+", "+(in==null));
		doc = documentBuilder.parse(in);
		in.close();
		return doc;
	};
	
	public String getSqlById(String id) {
		if(document==null) {
			initDoc();
		}
		String sql="";
		// DTD definition of id is required 
		Element sqlElement=document.getElementById(id);
		sql= sqlElement.getFirstChild().getNodeValue();
		return sql;
	}

    

	public static void main(String[] args) throws Exception {
		SqlUtil sqlUtil=new SqlUtil();
		String sql=sqlUtil.getSqlById("getDailyFraudSummary");
		System.out.println(sql);
	}

}
